//
//  ZpMainTabBar.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/24.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpMainTabBar.h"
@interface ZpMainTabBar ()
@property (nonatomic, weak) UIButton *btn;
@end
@implementation ZpMainTabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        UIButton *btn = [[UIButton alloc] init];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        self.btn = btn;
        [self addSubview:btn];
        [btn addTarget:self action:@selector(middleBtn) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

- (void)middleBtn{
    NSLog(@"中间的按钮被点击了");
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    CGFloat viewW = ScreenWidth / 5;
    CGFloat viewH = self.bounds.size.height;
    CGFloat viewY = 0;
    int i = 0;
    
    for (UIView * v in self.subviews)
    {
        if ([v isMemberOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            v.frame = CGRectMake(i * viewW, viewY, viewW, viewH);
            
            i += (i == 1 ? 2 : 1);
        }
    }
    
    self.btn.frame = CGRectMake(viewW * 2, viewY, viewW, viewH);
}
@end
